package warehouse;

/**
 *
 * @author Manolescu Razvan
 */
public class Index implements Comparable {

    double selectivity;
    String tableName, indexName;

    public Index(double selectivity, String tableName, String indexName) {
        this.selectivity = selectivity;
        this.tableName = tableName;
        this.indexName = indexName;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null) {
            return false;
        }

        if (o instanceof Index) {
            Index i = (Index) o;
            return i.tableName.equalsIgnoreCase(tableName)
                    && i.indexName.equalsIgnoreCase(indexName);
        }

        return false;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 53 * hash + (this.tableName != null ? this.tableName.hashCode() : 0);
        hash += 53 * hash + (this.indexName != null ? this.indexName.hashCode() : 0);
        return hash;
    }

    @Override
    public int compareTo(Object o) {
        Index i = (Index) o;
        return i.selectivity < selectivity ? -1 : 1;
    }

    @Override
    public String toString() {
        return tableName + "." + indexName + " -> " + selectivity;
    }
}
